package models

import (
	"gorm.io/gorm"
	"time"
	"user_srv/basic/config"
)

type Like struct {
	Id        uint           `gorm:"column:id;type:bigint(20) UNSIGNED;primaryKey;not null;" json:"id"`
	UserId    uint           `gorm:"column:user_id;type:bigint(20);comment:用户ID;not null;" json:"user_id"`                           // 用户ID
	VideoId   uint           `gorm:"column:video_id;type:bigint(20);comment: 视频ID;not null;" json:"video_id"`                        //  视频ID
	Status    uint           `gorm:"column:status;type:int(10) UNSIGNED;comment:点赞状态：1:已点赞，2:未点赞;not null;default:1;" json:"status"` // 点赞状态：1:已点赞，2:未点赞
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"`
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (l *Like) TableName() string {
	return "like"
}
func (l *Like) AddLike(db *gorm.DB) error {
	return db.Model(&Like{}).Create(&l).Error
}
func (l *Like) DeleLike(db *gorm.DB) error {
	return db.Model(&Like{}).Where("id = ?", l.Id).Delete(&l).Error
}
func (l *Like) GetLikeStatus() error {
	return config.DB.Where("user_id = ? AND video_id = ?", l.UserId, l.VideoId).Order("like_count > 7").Limit(1).Find(&l).Error
}
